﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPP_Service.Data;

namespace WPP_Console
{
    /// <summary>
    /// Interaction logic for BatchClearWindow.xaml
    /// Allows the user to mark all orders that have not been picked up
    /// as cleared so the system will no longer show them.
    /// </summary>
    public partial class BatchClearWindow : Window
    {
        public BatchClearWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// handles the clear button click. Takes the dates and feed them to the server to clear out the orders.
        /// </summary>
        /// <param name="sender">the sending object</param>
        /// <param name="e">event arguments</param>
        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {
            DateGroup dg = new DateGroup();
            dg.StartDate = (DateTime)dpFrom.SelectedDate;
            dg.EndDate = (DateTime)dpTo.SelectedDate;
            dg.DateType = DateType.BATCH_CLEAR;
            InvokeResponse resp = ServiceClient.BatchClear(dg);

            if (resp.ResponseCode == InvokeResponseCode.INVOKE_OK)
            {
                MessageBox.Show("Orders have been successfully cleared.");
            }
            else
            {
                MessageBox.Show("Web Package Pro has encountered and error\n\nCode: " + resp.ResponseCode.ToString() + "\n\nPlease contact your system administrator.");
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
